<template>
  <div>
    <el-table
      :data="tableList"
      border
      style="margin: 10px 0"
      v-loading="loading"
      tooltip-effect="dark"
      @selection-change="$emit('selectionChange', $event)"
    >
      <el-table-column type="selection" width="55"></el-table-column>
      <el-table-column
        prop="file_name"
        width="160"
        label="名称"
        align="center"
      ></el-table-column>
      <el-table-column prop="file_url" label="图片" width="140" align="center">
        <template slot-scope="scope">
          <el-image
            v-show="scope.row.file_url"
            :src="scope.row.file_url"
            fit="contain"
            style="width: 40px; height: 40px"
          >
          </el-image>
        </template>
      </el-table-column>
      <el-table-column
        prop="category"
        label="所属分类"
        width="140"
        align="center"
      >
        <template slot-scope="scope">
          <div>{{ scope.row.category?.name || "无 " }}</div>
        </template>
      </el-table-column>
      <el-table-column
        prop="upload_type"
        label="上传类型"
        width="140"
        align="center"
      >
        <template slot-scope="scope">
          <div>{{ upload_typeText(scope.row.upload_type) }}</div>
        </template>
      </el-table-column>
      <el-table-column
        prop="file_type"
        label="文件类型"
        width="140"
        align="center"
      >
      </el-table-column>
      <el-table-column prop="file_type" label="尺寸" width="140" align="center">
        <template slot-scope="scope">
          <div>宽：{{ scope.row.image_width }}</div>
          <div>高：{{ scope.row.image_height }}</div>
        </template>
      </el-table-column>
      <el-table-column
        prop="file_size"
        width="140"
        label="大小"
        align="center"
      ></el-table-column>
      <el-table-column
        prop="create_time"
        label="创建时间"
        width="160"
        align="center"
      >
      </el-table-column>
      <el-table-column
        label="操作"
        min-width="150"
        fixed="right"
        align="center"
      >
        <template slot-scope="scope">
          <el-button
            style="color: #67c23a"
            type="text"
            size="mini"
            @click="$emit('edit', scope.row)"
            >修改
          </el-button>
          <el-button
            style="color: red"
            type="text"
            size="mini"
            @click="$emit('del', scope.row)"
            >删除
          </el-button>
        </template>
      </el-table-column>
    </el-table>
    <pagination
      :page="page"
      :page_size="page_size"
      :total="total"
      @currentChange="currentChange"
      @sizeChange="sizeChange"
    ></pagination>
  </div>
</template>

<script>
export default {
  name: "myTable",
  data() {
    return {}
  },
  props: {
    tableList: {
      type: Array,
      default: () => [],
    },
    page: {
      type: Number,
      default: 1,
    },
    page_size: {
      type: Number,
      default: 10,
    },
    total: {
      type: Number,
      default: 0,
    },
    loading: {
      type: Boolean,
      default: true,
    },
  },
  computed: {
    upload_typeText() {
      return (upload_type) => {
        if (upload_type == 1) {
          return "后台"
        } else if (upload_type == 2) {
          return "平台"
        } else {
          return "用户端"
        }
      }
    },
  },
  methods: {
    currentChange(e) {
      this.$emit("currentChange", e)
    },
    sizeChange(e) {
      this.$emit("sizeChange", e)
    },
  },
}
</script>

<style lang="scss" scoped>
.text {
  color: $base-status-color;
}
</style>
